package com.evil.Servlet;

import com.evil.DAO.SendMessageDAO;
import com.evil.Data.Data;
import com.evil.Utils.PropertiesUtils;

import java.util.ArrayList;

/********************************************
 * 工程名：Eda
 * 包名：${PACKAGE_NAME}
 * 时间：16-9-5 下午1:37
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：消息推送
 ********************************************/
public class SendMessageServlet extends BaseServlet
{
    private String phone;
    private String imei;
    private String msgNum;

    @Override
    public void doPost()
    {
        phone = getParameter("phone");
        imei = getParameter("imei");
        msgNum = getParameter("msgNum");

        if (!phone.equals("") && !phone.equals(" "))
            findMsg();
    }

    private void findMsg()
    {
        SendMessageDAO dao = new SendMessageDAO();
        ArrayList<String> private_list = dao.find_private_msg(phone);

        log(private_list.size());

        if (private_list != null && private_list.size() > 0)
        {
            out.print(private_list.get(1) + "\n\n\n" + private_list.get(2));

            /*读取完成后删除此条私人公告 todo：以后可能设置标志位，尽量不要删除*/
            dao.delete_private_msg(phone);
        }
        else if (private_list.size() == 0)
        {
            ArrayList<String> public_list = dao.find_public_msg();

            if (public_list != null)
            {
                if (!public_list.get(0).equals(msgNum))
                {
                    out.print(public_list.get(0));
                    out.print( new PropertiesUtils().get("BREAKSTRING"));
                    out.print(public_list.get(1));
                }
                else
                    out.print("null");
            }
        }


    }


}
